package org.niu.listnode;

import java.util.LinkedHashSet;
import java.util.Set;

public class DeleteDuplicates {
    public ListNode deleteDuplicates (ListNode head) {
        // write code here
        Set<Integer> set = new LinkedHashSet<>();
        ListNode p = head;
        while(p!=null){
            set.add(p.val);
            p=p.next;
        }
        ListNode nHead = new ListNode(-1);
        ListNode tail = nHead;
        for (Integer integer : set) {
            ListNode t = new ListNode(integer);
            tail.next = t;
            tail=tail.next;
        }
        return nHead.next;
    }
}
